<template>
	<view class="apply">
		<view class="u-m-t-50">
			<u-steps :list="numList" :current="paneShow" mode='number' active-color='#FF9F42'
				un-active-color='#BFBFBF' />
			<!-- 基本信息 -->
			<BaseInfo v-show="paneShow == 0" ref='info_0' :sumbitShow='sumbitShow' :dataObj='dataObj'
				@stepsCallback='onStepsCallback' />
			<!-- 商户信息 -->
			<BusinessInfo v-show="paneShow == 1" ref='info_1' :sumbitShow='sumbitShow' :dataObj='dataObj'
				@stepsCallback='onStepsCallback' />
			<!-- 开户信息 -->
			<AccountInfo v-show="paneShow == 2" ref='info_2' :sumbitShow='sumbitShow' :dataObj='dataObj'
				@stepsCallback='onStepsCallback' @sumbit='onSumbit' />

		</view>
	</view>
</template>

<script>
	import BusinessInfo from './pane/businessInfo.vue'
	import AccountInfo from './pane/accountInfo.vue'
	import BaseInfo from './pane/baseInfo.vue'
	export default {
		components: {
			BusinessInfo,
			AccountInfo,
			BaseInfo
		},
		data() {
			return {
				dataForm: {},
				submitStatus: false,
				dataObj: {},
				paneShow: 0,
				sumbitShow: true,
				numList: [{
					name: '基本信息'
				}, {
					name: '商户信息'
				}, {
					name: '开户信息'
				}],
			};
		},

		onLoad(options) {
			if (options.sumbitShow == 'false') {
				this.sumbitShow = false
				this.initDataObj()
			}
			this.initDataObj()
		},
		onShow() {

		},
		methods: {
			onSumbit() {
				if (this.submitStatus) return
				this.submitStatus = true
				// 获取三个组件里面的表单值
				let dataForm = {
					appid: 'wx5d1de9e87e029220',
				}
				this.numList.forEach((el, index) => {
					Object.assign(dataForm, this.$refs[`info_${index}`].dataForm)
				})

				this.$adminPost('Applyment4subApplyment', {
					agent: 0,
					salesman: 0,
					business_id: this.vuex_user.pk_id,
					supplier_id: this.vuex_adminuser.supplier_id,
				}, JSON.stringify(dataForm)).then(res => {
					this.onBack(true)
					this.$toast('申请成功')
				}).catch(() => {
					this.onBack()
				})
			},

			onBack(judeg) {

				if (judeg) {

					setTimeout(() => {
						uni.navigateBack({
							delta: 1
						})
					}, 1500)
					return
				}

				if (!judeg) this.submitStatus = false
			},
			onStepsCallback(number) {
				this.paneShow = number
			},
			initDataObj() {
				// 获取当前页面栈
				let pages = getCurrentPages();
				// 最后一个元素为当前页面,-1 为当前页面的数据 ,-2 为你上一页的数据 
				let prevPage = pages[pages.length - 2]
				this.dataObj = prevPage.$vm.$refs.baseRef.dataObj.wechat_json
			},
		}
	};
</script>
<style>
	page {
		background-color: #f5f5f5;

	}
</style>
<style lang="scss" scoped>
	.apply {
		padding: 0 26rpx;
	}

	::v-deep .u-form-item__message {
		padding-left: 0 !important;
		margin-left: auto !important;
	}
</style>
